function y = filterEEG(data, Wn)

% validate arguments
failIfFalse(isvector(data), 'Data should be in a 1xn vector.');
failIfFalse((isvector(Wn) && (size(Wn, 2) == 2)), 'Wn should be a two-element vector');

order = 128;

data = data';

% handle right shifting ...
lastSample = data(size(data, 1));

shiftLength = order/2;

filler = zeros(shiftLength, 1);
filler(1:end) = lastSample; 
data = [data; filler];


% design a finite impulse response (FIR) bandpass filter
b = fir1(order, Wn);

% implement the filter and apply it to data
a = 1;
y = filter(b, a, data);

% delete first samples to get a signal of the original length
y(1:shiftLength) = [];
